#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>

#include "BDPcCoder_global.h"
#include "BDPcCoder.h"


typedef enum E_MSGTYPE_
{
  E_MSGTYPE_ICP = 0,
  E_MSGTYPE_TCI,
  E_MSGTYPE_GGA,
} E_MSGTYPE;
typedef struct T_MSG_
{
  E_MSGTYPE eType;
  void  *pMsg;
} T_MSG;


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
  Q_OBJECT

public:
  explicit MainWindow(QWidget *parent = 0);
  ~MainWindow();

  //! 初始化
  bool  Init();
  //! 释放
  void  Free();
  //! 发送
  int   SendICR(const T_BDICRDATA *tData);      //! ICR
  int   SendMSS(const T_BDMSSDATA *tData);      //! MSS
  int   SendTCQ(const T_BDTCQDATA *tData);      //! TCQ
  int   SendTBQ(const T_BDTBQDATA *tData);      //! TCQ
  bool  SendBDData(const T_BDRSDATA &tData);

  bool  GetSerialPortStatus();
  void  QStringToChar(QString src, char *dest);

private:
  Ui::MainWindow *ui;
  BDPcCoder *m_cBDPcCoder = NULL;
  QSerialPort *m_cSerial = NULL;      //! 串口

private slots:
  void  RecvBDDataSlot();
  void  WriteDataSlot(const T_BDRSDATA &tData);
  void  ReadQueueSlot();
  void  on_pushButtonSeriportOpen_clicked();
  void  on_comboBoxSendCmd_activated(const QString &arg1);
  void  on_pushButtonSendCmd_clicked();

  void  insertDBReceive(const QString &userID, const QString &content, const QString &time);
  void  checkDBSent();
  void  pushButtonSendCmdToDB(const QString &infoID, const QString &sCmd);

signals:
  void  WriteDataSignal(const T_BDRSDATA &tData);
};

#endif // MAINWINDOW_H
